Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2/n] add newtype wrappers to ensure config identifier validity #69

Conversation

sunshowers
Copy link
Collaborator

@sunshowers sunshowers commented Dec 20, 2024

I'm going to add some more identifiers soon, and I wanted to make sure at
deserialize time that they were somewhat well-formed. We restrict ourselves to
ASCII at the moment, which is fine.

Add three newtype wrappers -- one each for package, service and preset names.

Depends on:

Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1

[skip ci]
Created using spr 1.3.6-beta.1
@sunshowers sunshowers changed the base branch from main to sunshowers/spr/main.add-a-newtype-wrapper-to-ensure-config-identifier-validity December 20, 2024 10:20
@sunshowers sunshowers changed the title add a newtype wrapper to ensure config identifier validity [2/n] add a newtype wrapper to ensure config identifier validity Dec 20, 2024
Created using spr 1.3.6-beta.1

[skip ci]
Created using spr 1.3.6-beta.1
use serde::{Deserialize, Serialize};
use thiserror::Error;

/// A unique identifier for a configuration parameter.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to codify this a little better, thanks!

}
}

impl<'de> Deserialize<'de> for ConfigIdent {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why manually implement Deserialize but not Serialize?

Is it worth adding a test that we can serialize -> deserialize -> re-serialize?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deserialize must go through validation, while serialization doesn't have to. Definitely worth writing a test for.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests and a comment explaining this.

@@ -12,10 +12,12 @@ use std::path::Path;
use thiserror::Error;
use topological_sort::TopologicalSort;

use super::ConfigIdent;

/// Describes a set of packages to act upon.
///
/// This structure maps "package name" to "package"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth it to make a thin wrapper around ConfigIdent to label this as a PackageName specifically?

I'm assuming that with other configuration parameter usage, there will be other uses of ConfigIdent that are semantically different.

(If you want to punt this beyond this PR, I'm also fine with that)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per discussion in DMs, ended up creating three newtypes -- one each for package names, service names and preset names.

sunshowers and others added 2 commits December 20, 2024 23:12
Created using spr 1.3.6-beta.1

[skip ci]
Created using spr 1.3.6-beta.1
@sunshowers sunshowers changed the base branch from sunshowers/spr/main.add-a-newtype-wrapper-to-ensure-config-identifier-validity to main December 20, 2024 23:14
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
@sunshowers sunshowers changed the title [2/n] add a newtype wrapper to ensure config identifier validity [2/n] add newtype wrappers to ensure config identifier validity Dec 21, 2024
@sunshowers sunshowers merged commit d0ecc79 into main Dec 21, 2024
5 checks passed
@sunshowers sunshowers deleted the sunshowers/spr/add-a-newtype-wrapper-to-ensure-config-identifier-validity branch December 21, 2024 00:03
sunshowers added a commit that referenced this pull request Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants